<div class="modal fade bs-modal-lg" id="modelContent">
	<div class="modal-dialog modal-lg">
        <div class="modal-content"></div>
    </div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
	    <div class="caption"><i class="fa fa-cog"></i>账房 > 单据管理 > 发票 </div>
		<div class="tools">
			<a href="javascript:;" class="collapse right" data-original-title="" title=""> </a>
    	</div>
    	<div class="actions">
			<a href="javascript:;" class="btn white btn-sm ajax-search"><i class="fa fa-search"></i> 查询 </a>
			<a href="javascript:;" class="btn white btn-sm search-reset"><i class="fa fa-eraser"></i> 清除 </a>
		</div>
	</div>
	<div class="portlet-body form">
	   	<form action="orderInvoice/list" class="form-horizontal" method="get" id="searchForm" onsubmit="return false">
	    	<input type="hidden" name="invoiceType" value="$!invoiceType" >
			<div class="form-body">
				<div class="row">
					<div class="form-group">
						注：系统开票金额自动视为订单中买家支付现金的金额，发票只能开一次。</br>
      					开票有两种状态：1、申请中：订单含发票信息已付款且已完成订单、订单已付款后台代开发票且订单已完成订单、个人中心申请发票。</br>
                                   2、已开票：后台开票确认后改变为“已开。票”状态
					</div>
					<div class="form-group">
						<div class="col-md-3">
							<label class="col-md-4 control-label">所属企业：</label>
							<div class="col-md-8">
						    	<input type="text" class="form-control" name="companyName" value="$!companyName">
							</div>
						</div>
						<div class="col-md-3">
							<label class="col-md-4 control-label">发票抬头：</label>
							<div class="col-md-8">
						    	<input type="text" class="form-control" name="title" value="$!title">
							</div>
						</div>
						<div class="col-md-2">
							<label class="col-md-4 control-label">开票金额：</label>
							<div class="col-md-8">
						    	<input type="number" class="form-control" name="payment" value="$!payment">
							</div>
						</div>
						<div class="col-md-2">
							<label class="col-md-4 control-label">开票状态：</label>
							<div class="col-md-8">
								<select name="state" class="form-control">
							    	<option value=""></option>
									<option value="0" #if($state==0) selected="selected" #end> 申请中</option>
									<option value="1" #if($state==1) selected="selected" #end>已开票</option>
								</select>
							</div>
						</div>
					</div>
					<div class="form-group">
						<div class="col-md-2">
							<label class="control-label col-md-6">申请时间：</label> 
							<label class="col-md-6">
								<input class="form-control" type="text" name="startTime" id="startTime" value="$!startTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
						<div class="col-md-2">
							<label class="control-label col-md-2">至：</label> 
							<label class="col-md-6">
								<input class="form-control" type="text" name="endTime" id="endTime" value="$!endTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
						<div class="col-md-2">
							<label class="control-label col-md-6">开票时间：</label> 
							<label class="col-md-6">
								<input class="form-control common-date-datepicker" type="text" name="makeStartTime" id="makeStartTime" value="$!makeStartTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
						<div class="col-md-2">
							<label class="control-label col-md-2">至：</label> 
							<label class="col-md-6">
								<input class="form-control common-date-datepicker" type="text" name="makeEndTime" id="makeStartTime" value="$!makeStartTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
					</div>
	    		</div>
			</div>
		</form>
	</div>
</div>

<div class="portlet box green">
    <div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>数据列表</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
		<div class="actions">
			<a onclick="javascript:checkBatchPass();" class="btn white btn-sm" data-toggle="modal"><i class="fa fa-check"></i> 确定开票 </a>
			<a  id="export" class="btn white btn-sm"  ><i class="fa fa-cloud-download"></i> 导出 </a>
		</div>
    </div>
    <div class="portlet-body">
		<div class="tabbable-line ">
			<ul class="nav nav-tabs ">
				<li #if(!$invoiceType) class="active checkTab" #end><a href="orderInvoice/list" class="ajaxify">全部</a></li>
				<li #if($invoiceType=='ORDINARY') class="active checkTab" #end ><a href="orderInvoice/list?invoiceType=ORDINARY" class="ajaxify"> 普通发票</a></li>
				<li #if($invoiceType=='VALUEADDED') class="active checkTab" #end ><a href="orderInvoice/list?invoiceType=VALUEADDED" class="ajaxify"> 增值税发票</a></li>
			</ul>
			
			<div class="tab-content">
				<div class="tab-pane active form">
					<div class="table-container table-scrollable">
						<table class="table table-bordered table-hover icheck-table" id="productTable">
							<thead>
									<tr>
					  		 			<th style="width: 20px">
											<input type="checkbox" class="icheck group-icheck"/>
										</th>
						  		 			<th>申请时间</th>
						  		 			<th>会员</th>
						  		 			<th>所属企业</th>
						  		 			<th>开票状态</th>
						  		 			<th>开票人</th>
						  		 			<th>开票金额(￥)</th>
						  		 			<th>发票抬头</th>
						  		 			<th>社会统一信用代码</th>
						  		 			<th>开票时间</th>
										<th class="col-md-2">操作</th>
									</tr>
								</thead>
								<tbody>
								#foreach($item in $pageOrderInvoice.result)
								#set($company=$companyMap.get($item))
						 				<tr>  
									    <td>
									    	<input type="checkbox" name="checkboxes" class="icheck" value="$!item.id" />
								    	</td>
									    <td>$!item.timeString</td>
									    <td>$!item.memberId</td>
									    <td>$!company.name</td>
									    <td>#if($item.state == 0) 申请中 #else 已开票 #end</td>
									    <td>$!item.name</td>
									    <td>$!item.payment</td>
									    <td>$!item.title</td>
									    <td>$!item.socialCreditCode</td>
									    <td>$!item.makeTimeString</td>
						    			<td>
						    				<a  href="#modelContent"  data-toggle="modal" thref="/orderInvoice/detail?id=$!item.id" class=" btn green btn-outline btn-sm  ajax-model-get " >操作</a>
									    </td>		  			
						 				</tr>
								#end
								</tbody>
							</table>
					</div>
					#set($page= $pageOrderInvoice)
					#set($pageUrl="/orderInvoice/list?$!queryString&pageNo=")
					#parse("_page.htm")
				</div>
				<form id="excel_download" action="/orderInvoice/exportExcel"
					class="hide" method="POST">
					<input type="hidden" name="sId" id="sId">
					<button type="submit"></button>
				</form>
			</div>
		</div>
    </div>
</div>
<script type="text/javascript">
     $("input[name=id]").focus();
</script>
<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript">
/**
 * 导出报价单
 */
$("#export").click(function(){
	var array = new Array()
	var target= $("input[name='checkboxes']");
	//循环加入数组
	
		$.each(target,function(i,v){
			if(v.checked){
				array.push($(v).val());
			}
		});
	if(array.length>0){
		$("#sId").val(array);
		$("#excel_download").submit();
	}else{
		toastr.warning("请勾选要导出的发货单！");
	}
})
</script>
<script type="text/javascript">
function checkBatchPass(){
	var params = "";
	$("input[name='checkboxes']").each(function() {
	    if($(this).prop('checked')) {
	        params = params + $(this).val() +",";
	    }
	});
	if(params == ""){
		toastr.warning("批量确定开票选择为空！");
		return;
	}
	params = params.substring(0,params.length-1);
	
	var formData = new FormData();
    formData.append("checkboxes", params);
	$.ajax({
		url: "/orderInvoice/checkBatchPass",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(res) {
			if(res.code==0){
				$(".checkTab").eq(0).children("a:eq(0)").click();
				toastr.success(res.msg);
			}
		}
	})
}
</script>